package com.project.psc.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.psc.bean.StoreBean;
import com.project.psc.dto.SupplierDto;
import com.project.psc.service.IStoreService;
import com.project.psc.util.SupplierThreadLocal;
import com.project.psc.vo.AddGoodsVo;
import com.project.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("store")
public class StoreController {
    @Autowired
    private IStoreService storeService;

    @RequestMapping("cutByItem")
    public ResultVo cutByItem(Integer pageNO, String goodsName, String type, String brand) {
        SupplierDto loginUser = SupplierThreadLocal.getSupplier();
        IPage<StoreBean> ip = storeService.cutByItem(pageNO, goodsName, type, brand, loginUser.getId());
        return ResultVo.ok(ip);
    }


    @RequestMapping("findById")
    public ResultVo findById(String goodsId) {
        SupplierDto loginUser = SupplierThreadLocal.getSupplier();
        AddGoodsVo byId = storeService.findById(goodsId, loginUser.getId());
        return ResultVo.ok(byId);
    }

    @RequestMapping("delete")
    public ResultVo delete(Long id) {
        storeService.delete(id);
        return ResultVo.ok();
    }

    @RequestMapping("add")
    public ResultVo add(AddGoodsVo goodsVo) {
        SupplierDto loginUser = SupplierThreadLocal.getSupplier();
        storeService.add(goodsVo,loginUser.getId());
        return ResultVo.ok();
    }

    @RequestMapping("findAllType")
    public ResultVo findAllType() {
        List<String> type = storeService.findAllType();
        return ResultVo.ok(type);
    }

    @RequestMapping("findAllBrand")
    public ResultVo findAllBrand() {
        List<String> b = storeService.findAllBrand();
        return ResultVo.ok(b);
    }

    @RequestMapping("updateNum")
    public ResultVo updateNum(Long goodsInfoId, Integer num) {
        storeService.updateNum(goodsInfoId, num);
        return ResultVo.ok();
    }

    @RequestMapping("deleteGoods")
    public ResultVo deleteGoods(Long goodsInfoId) {
        storeService.deleteGoods(goodsInfoId);
        return ResultVo.ok();
    }

}
